#include "threadencoder.h"

#include <QDebug>


ThreadEncoder::ThreadEncoder(QObject *parent) : QThread(parent)
{
    qDebug()<<" ThreadEncoder initial ";

}

ThreadEncoder::~ThreadEncoder()
{
   close(encoder_fd);
}


int ThreadEncoder::encoderDev(void)
{
    int count;
    struct input_event ev_key;

    encoder_fd = open(ENCODER_DEV, 0);
    if (encoder_fd < 0)
    {
        perror("error open encoder device!\n");
//        exit(1);
        return 0;
    }

    while(1)
    {
        count = read(encoder_fd, &ev_key, sizeof(struct input_event));

        if (EV_KEY == ev_key.type)
        {

//            if(m_pCustomInstace->m_pnAllFlagList[EM_AFT_LOCK_SCREEN_FLAGE] == EM_CF_ON || (m_pCustomInstace->m_pnAllFlagList[EM_AFT_TERMINATE_OVER_LAYER] == EM_CF_ON))
//            {
//                // 如果是编码器旋转事件，则发送信号，把编码器事件的 code 和 value 值发送出去
                emit sendEncoderSig(ev_key.code, ev_key.value /10 );
//            }
//            else
//            {
//                if(EM_CF_OFF == m_pCustomInstace->m_psMessageBoxInfo->nIsShowMessage)
//                {
//                    // 如果是编码器旋转事件，则发送信号，把编码器事件的 code 和 value 值发送出去
//                    emit sendEncoderSig(ev_key.code, ev_key.value /10 );
//                }
//            }




            //printf("ThreadEncoder ---  type:%d,code:%d,value:%d\n", ev_key.type, ev_key.code, ev_key.value /10 );
        }

        if (EV_SYN == ev_key.type)
        {
            //printf("syn event\n");
        }


        msleep(100);
    }

    return 0;

}

void ThreadEncoder::run()
{
    encoderDev();

}

